package com.car.serve.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.car.commons.core.model.Result;
import com.car.commons.core.util.JwtUtil;
import com.car.commons.web.util.WebUtil;
import com.car.serve.Param.PageServeShouHouParam;
import com.car.serve.Param.PageStoresShouHouLogParam;
import com.car.serve.Param.PageStoresShouHouParam;
import com.car.serve.entity.ServeShouhou;
import com.car.serve.entity.ServeShouhouLog;
import com.car.serve.exception.ServeException;
import com.car.serve.form.PageServeShouHouForm;
import com.car.serve.form.PageStoresShouHouForm;
import com.car.serve.form.PageStoresShouHouLogForm;
import com.car.serve.service.ServeShouhouLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.security.sasl.SaslException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 董旭
 * @since 2024-08-28
 */
@RestController
@RequestMapping("/serveShouhouLog")
@Api(tags = "售后日志信息")
public class ServeShouhouLogController {

    @Resource
    private ServeShouhouLogService serveShouhouLogService;


    @PostMapping("/findByIdLog")
    @ApiOperation(value = "根据售后ID查询售后日志信息")
    public Result findByIdLog(Integer shouHouId)throws Exception{
        ServeShouhouLog byId = serveShouhouLogService.getById(shouHouId);
        if (byId==null)throw new ServeException(3000,"不存在售后日志");
        return Result.getResult().setMsg("查询成功").setData(byId);
    }

    @PostMapping("/findBuyIdShouHouLogPage")
    @ApiOperation(value = "根据用户ID查询当前用户售后日志信息分页查询")
    public Result findBuyIdShouHou(@RequestBody PageServeShouHouForm form)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer userId = JwtUtil.getUserId(token);
        PageServeShouHouParam param = BeanUtil.toBean(form, PageServeShouHouParam.class);
        param.setUserId(userId);
        Page<ServeShouhouLog> buyIdShouHouLogPage = serveShouhouLogService.findBuyIdShouHouLogPage(param);
        return  Result.getResult().setMsg("查询成功").setData(buyIdShouHouLogPage);
    }

    @PostMapping("/getShouhouLogPage.md")
    @ApiOperation(value = "查询当前门店所有订单售后日志")
    public Result getShouhouLogPage(@RequestBody PageStoresShouHouLogForm form)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer clerkId = JwtUtil.getClerkId(token);
        PageStoresShouHouLogParam param = BeanUtil.toBean(form, PageStoresShouHouLogParam.class);
        param.setClerkId(clerkId);
        Page<ServeShouhouLog> orderInfoPage = serveShouhouLogService.getShouhouLogPage(param);
        return  Result.getResult().setMsg("查询成功").setData(orderInfoPage);
    }
}

